﻿Public Class AU480
    Sub ResultDataParse(ByVal strInput As String, ByRef clsPatient As PatientInformation, ByVal Rerun As Boolean)
        Dim tmp As New PatientInformation.ResultStruct
        ' clsPatient.SpecimenID = strInput.Substring(18, 30).Trim 'Lấy thông tin barcode, lấy từ ký tự 13, lấy thêm 20 ký tự nữa
        'clsPatient.SpecimenID = strInput.Substring(13, 4).Trim
        'for barcode 12 ky tu
        clsPatient.SpecimenID = strInput.Substring(14, 20).Trim()
        'for barcode 4 ky tu
        ' Dim strtmp As String = strInput.Substring(22)           'Lấy thông tin kết quả, lấy từ ký tự 64
        'for barcode 12 ky tu
        Dim strtmp As String = strInput.Substring(38)
        'Dim strtmp As String = strInput.Substring(84)          
        Do

            tmp.TestCode = strtmp.Substring(0, 3)
            'for barcode 4 ky tu
            tmp.DataValue = Trim_All(strtmp.Substring(20, 7)).Replace("r", "").Replace("h", "").Replace("N", "").Replace("P", "")
            ' tmp.DataValue = Trim_All(strtmp.Substring(19, 3)).Replace("r", "").Replace("h", "")
            'FOR BARCODE 12 KY TỰ
            'tmp.DataValue = Trim_All(strtmp.Substring(19, 7)).Replace("r", "").Replace("h", "").Replace("N", "")
            strtmp = strtmp.Remove(0, 27)
            clsPatient.ResultArray.Add(tmp)

        Loop Until strtmp.Length < 10
    End Sub

    Public Function CreatOrderString(ByVal SID As String, ByVal TestID As String(), ByVal RackNo As String, ByVal PosNo As String, ByVal SampleNo As String, ByVal Rerun As Boolean) As String
        Dim sTemp() As String
        Dim i As Byte
        ReDim sTemp(8 + TestID.GetLength(0))
        sTemp(0) = Chr(STX)
        If Rerun Then
            sTemp(1) = "SH"
        Else
            sTemp(1) = "S "
        End If

        sTemp(2) = RackNo 'Rack No.
        sTemp(3) = PosNo      'Cup Pos
        sTemp(4) = " "      'Sample Type
        sTemp(5) = SampleNo   'Sample No.
        ''For AU480
        sTemp(6) = SID.PadLeft(20) & "    "     'dummy
        ''For AU400
        'sTemp(6) = SID.PadLeft(20) & "    "     'dummy
        'Set sample id trong phần mềm AU480 là 4 digit với barcode là 4 ký tự
        'sTemp(6) = SID.Substring(6, 4) & "    "     'dummy
        ''For AU400
        'sTemp(7) = "E0"         'Last & no sex

        ''For AU480
        sTemp(7) = ""         'Last & no sex
        sTemp(8) = "E"
        'sTemp(8) = [String].Concat(Space(3), Space(2), Format(Now, "dd/MM/yyyy").PadLeft(20))
        'sTemp(8) = [String].Concat(Space(3), Space(2), Format(Now, "dd/MM/yyyy").PadLeft(20)) & strName.Padleft(20)

        For i = 0 To TestID.GetLength(0) - 1
            sTemp(9 + i) = TestID(i).PadLeft(3) & "0"
        Next
        Dim s As String = [String].Concat([String].Concat(sTemp))
        s = [String].Concat(s, Chr(ETX))
        Return s
        ' Threading.Thread.Sleep(2000)
    End Function

    Function Trim_All(ByVal vString As String) As String
        vString = Replace(vString, " ", "")
        Return vString
    End Function
End Class
